<template>
  <div class="rentertopaid content-bg">
    <el-table :data="tableData"
              border
              :fit="true"
              style="width: 100%">
      <el-table-column label="房屋id"
                       prop="houseId">
      </el-table-column>
      <el-table-column label="地址"
                       prop="address">
      </el-table-column>
      <el-table-column label="应缴租金"
                       prop="price">
      </el-table-column>
      <el-table-column label="应缴租金日期"
                       prop="date">
      </el-table-column>
      <el-table-column label="租客姓名"
                       prop="name">
      </el-table-column>
      <el-table-column label="状态"
                       prop="status">
      </el-table-column>
      <el-table-column label="操作" v-if="role==='renter'">
          <template slot-scope="scope">
            <el-button size="mini"
                       type="primary"
                       @click="paymentPrice(scope.$index, scope.row)">支付租金</el-button>
          </template>
    </el-table-column>
    </el-table>
    <div class="pagination-box">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="pagination.currentPage"
        :page-size="pagination.pageSize"
        layout="total, prev, pager, next"
        :total="pagination.total">
      </el-pagination>
    </div>
  </div>
</template>
<script lang="js">
import axios from "axios";

export default {
  name: 'rentertopaid',
  data(){
    return {
      tableData: [],
        role:'',
      pagination: {//分页相关模型数据
        currentPage: 1,//当前页码
        pageSize: 10,//每页显示的记录数
        total: 0,//总记录数
        type:"",
        name:"",
        description:"",
      }
    }
  },
  created(){
    this.role = this.$store.state.userInfo.role;
    this.getAll()
  },
  mounted:{
    // 获取数据列表
  },
  methods: {
    getAll: function (){
      axios.get("/topaid/"+this.pagination.currentPage).then((res)=>{
        if (res.data.code === 1){
          this.tableData = res.data.data.records
          this.pagination.currentPage = res.data.data.current
          this.pagination.total = res.data.data.total
          this.pagination.pageSize = res.data.data.size
        }
      })
    },
    pay: function ($index,row){
      axios.get("/topaid/"+row.id()).then((res)=>{
        console.log(row.id)
      })
    },
    getRenterToPaidList(){

      //访问接口
    },
    // 支付租金
    paymentPrice($index,row){
      this.$confirm('确定要支付吗?', '支付租金', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        }).then(() => {
          this.pay($index,row)
          // 访问接口
          this.$alert('租金支付成功，可在已缴租金中查看', '支付成功', {
          confirmButtonText: '确定',
          callback: action => {
            this.$router.push({path:'/renterpaided'})
          }
        });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消'
          });
        });
      },
  //切换页码
  handleCurrentChange(currentPage) {
    this.pagination.currentPage = currentPage;
    this.getAll();
  },
    }
}
</script>
<style lang="scss" scoped>
</style>
